package geotransform.tools;

import java.io.*;
import java.lang.reflect.Array;
import java.util.*;

import geotransform.*;
import geotransform.coords.*;
import geotransform.datum.*;
import geotransform.ellipsoids.*;
import geotransform.transforms.*;


public class ElementoEDP {
	private String luminaria, nLampadas, fases, propEmpresa, obs, faturar; //read only
	public String id, coordX, coordY, lampada;
	public Utm_Coord_3d coordUTM;
	public Gdc_Coord_3d coordGeo;
	public char tipo;
	
	
	public ElementoEDP(ElementoEDP e, String X, String Y, String L) throws Exception{
		tipo = e.tipo;
		id = e.id;
		coordX = X;//tem que estar multiplicada por 100!
		coordY = Y;//tem que estar multiplicada por 100!
		luminaria = e.luminaria;
		lampada = L;
		nLampadas = e.nLampadas;
		fases = e.fases;
		propEmpresa = e.propEmpresa;
		obs = e.obs;
		faturar = e.faturar;
		
		double x,y;
		x = Double.parseDouble(coordX)/100;
		y = Double.parseDouble(coordY)/100;
		coordUTM = new Utm_Coord_3d(x,y,0,e.coordUTM.zone,e.coordUTM.hemisphere_north);
		coordGeo = ConvertDatum.SAD69toWGS84(ConvertCoordSystem.utmToGeo(this.coordUTM, "sad"));
	}
	
	public ElementoEDP(String s, char t, int utmZone) throws InvalidObjectException, Exception{
		InvalidObjectException e = new InvalidObjectException("Arquivo de entrada com formato invalido");
		if(s.split("\\*").length < 10) throw e;
		
		tipo = t;
		id = s.split("\\*")[0];
		coordX = s.split("\\*")[1];
		coordY = s.split("\\*")[2];
		luminaria = s.split("\\*")[3];
		lampada = s.split("\\*")[4];
		nLampadas = s.split("\\*")[5];
		fases = s.split("\\*")[6];
		propEmpresa = s.split("\\*")[7];
		obs = s.split("\\*")[8];
		faturar = s.split("\\*")[9];
		
		double x,y;
		x = Double.parseDouble(coordX)/100;
		y = Double.parseDouble(coordY)/100;
		coordUTM = new Utm_Coord_3d(x,y,0,(byte)utmZone,false);
		coordGeo = ConvertDatum.SAD69toWGS84(ConvertCoordSystem.utmToGeo(this.coordUTM, "sad"));
	}
	
	public String toString(){
		return (id + "*" + coordX + "*" + coordY + "*" + luminaria + "*" + lampada + "*" + nLampadas + "*" + fases + "*" + propEmpresa + "*" + obs + "*" + faturar + "*");
	}
	
	public Utm_Coord_3d getCoordUTM() {
		return this.coordUTM;
	}
	
	public Gdc_Coord_3d getCoordGeo() {
		return this.coordGeo;
	}
}
